#ifndef AGI4C_H
#define AGI4C_H

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>

#define AGIRES_OK 200

#define AST_STATE_DOWN 0
#define AST_STATE_RESERVED 1
#define AST_STATE_OFFHOOK 2
#define AST_STATE_DIALING 3
#define AST_STATE_RING 4
#define AST_STATE_RINGING 5
#define AST_STATE_UP 6
#define AST_STATE_BUSY 7
#define AST_STATE_DIALING_OFFHOOK 8
#define AST_STATE_PRERING 9

#define MAX_REQUEST 100

struct st_keyval {
  char *key;
  char *val;
};
typedef struct st_keyval KEYVAL;

struct st_agi_result {
  char *channel;
  char *command;
  int code;
  char *data;
  char *more;
  char *result;
};
typedef struct st_agi_result AGI_RESULT;

char *substring(char *string, int position, int length);
char *trim(char *src);
char *trim_mask(char *src, char *m);

char *agi_readline();
char *agi_readstring();
void agi_collect_request();
char *agi_request(char *name);
AGI_RESULT *agi_evaluate(char *command);
AGI_RESULT *agi_answer();
AGI_RESULT *agi_hangup(char *channel);
AGI_RESULT *agi_exec(char *application, char *options);
AGI_RESULT *agi_exec_dial(char *type, char *identifier, char *timeout, char *options, char *url);
AGI_RESULT *agi_stream_file(char *filename, char *escape_digits);
AGI_RESULT *agi_text2wave(char *text, char *escape_digits);
AGI_RESULT *agi_mp3togsm(char *filename, char *escape_digits);
AGI_RESULT *agi_vnspeak(char *textfile, char *escape_digits);
AGI_RESULT *agi_vnspeak_viqr(char *text, char *escape_digits);
AGI_RESULT *agi_play_mp3(char *mp3file);
char *agi_vnspeak_file(char *textfile);
char *agi_vnspeak_viqr_file(char *text);
char *agi_mp3togsm_file(char *filename);
void agi_set_channel(char *src);
AGI_RESULT *agi_get_data(char *filename, char *timeout, char *max_digits);
char *agi_text_input(char *mode);
char keypress(char c, int n, char *mode);
AGI_RESULT *agi_say_punctuation(char *text, char *escape_digits);
KEYVAL **agi_makechoicelist(int choice_count);
void agi_addchoice(KEYVAL **choicelist, int no, char *key, char *prompt);
char *agi_menu(KEYVAL **choicelist, int choice_count);
char *agi_text2wave_file(char *text);
char *agi_get_variable(char *name);

#endif //AGI4C